<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	layout:decorate="admin/fragments/layout"
	th:with="title='资源管理',active='resource'">

<section layout:fragment="header">
	<h1>资源管理</h1>
</section>

<section layout:fragment="content">

	<div class="box box-primary">
		<div class="box-header">
			<a class="btn btn-sm btn-success" href="/admin/resource/add">新增</a>
		</div>
		<div class="box-body">
			<table id="resourceTab" class="table table-bordered table-striped">
				<thead>
					<tr>
						<th>编号</th>
						<th>资源名称</th>
						<th>资源key</th>
						<th>资源url</th>
						<th>类型</th>
						<th>排序</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<tr th:each="resource : ${list}">
						<td th:text="${resource.id}"></td>
						<td th:text="${resource.sourceName}"></td>
						<td th:text="${resource.sourceKey}"></td>
						<td th:text="${resource.sourceUrl}"></td>
						<td th:text="${resource.type}"></td>
						<td th:text="${resource.sort}"></td>
						<td><a class="btn btn-sm btn-success"
							th:href="@{'/admin/resource/edit/'+${resource.id}}">修改</a>
							<button class="btn btn-sm btn-danger"
								th:onclick="'del('
									+ ${resource.id}
									+ ')'">删除</button></td>
					</tr>
				</tbody>
			</table>
		</div>

	</div>
</section>

<script layout:fragment="script">
	function del(id) {
		layer.confirm('确定删除吗?', {
			icon : 3,
			title : '提示'
		}, function(index) {
			$.ajax({
				type : "POST",
				dataType : "json",
				url : "/admin/resource/delete/" + id,
				success : function(res) {
					layer.msg(res.message, {
						time : 2000
					}, function() {
						location.reload();
					});
				}
			});
		});
	}

	$(document).ready(function() {
		//debugger;
		var tab = $('#resourceTab').DataTable({
			language : {
				url : '/assets/plugins/datatables.net/Chinese.json'
			},
			processing : true,
			serverSide : false,
			order : [ [ 0, "asc" ] ],
			/* 	ajax : {
					url : "/admin/resource/list",
					type : "POST"
				}, 
				columns : [ {
					data : 'sourceName'
				}, {
					data : 'sourceKey'
				}, {
					data : 'sourceUrl'
				}, {
					data : 'type'
				}, {
					data : 'sort'
				} ],*/
			columnDefs : [
			/* 	{
					render : function(data,
							type, row) {
						return '<a class="btn btn-sm btn-success" href="/admin/resource/edit/'+row.id+'">修改</a>  <button class="btn btn-sm btn-danger" onclick="del('
								+ row.id
								+ ')">删除</button>';
					},
					targets : -1
				}, */
			{
				"orderable" : false,
				"targets" : -1
			}, {
				"searchable" : false,
				"targets" : -1
			} ]
		});
	});
</script>
</html>